package net.panda.pandatools;

import android.content.Intent;
import android.os.BatteryManager;

public class BatteryStatus {
	  
	public String getStatus(Intent batteryStatus) {
		
        // Are we charging / charged?  
        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);  
        String strStatus;
        if (status == BatteryManager.BATTERY_STATUS_CHARGING){
         strStatus = "Charging";
        } else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING){
         strStatus = "Dis-charging";
        } else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING){
         strStatus = "Not charging";
        } else if (status == BatteryManager.BATTERY_STATUS_FULL){
         strStatus = "Full";
        } else {
         strStatus = "Unknown";
        }
        
        int health = batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1);
        String strHealth;
        if (health == BatteryManager.BATTERY_HEALTH_GOOD){
         strHealth = "Good";
        } else if (health == BatteryManager.BATTERY_HEALTH_OVERHEAT){
         strHealth = "Over Heat";
        } else if (health == BatteryManager.BATTERY_HEALTH_DEAD){
         strHealth = "Dead";
        } else if (health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
         strHealth = "Over Voltage";
        } else if (health == BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE){
         strHealth = "Unspecified Failure";
        } else{
         strHealth = "Unknown";
        }
        
        int plug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        String strPlug;
        if (plug == BatteryManager.BATTERY_PLUGGED_AC){
        	strPlug = "A.C.";
        } else if (plug == BatteryManager.BATTERY_PLUGGED_USB){
        	strPlug = "USB.";
        } else if (plug == BatteryManager.BATTERY_PLUGGED_WIRELESS){
        	strPlug = "WIRELESS";
        } else{
        	strPlug = "UnPlugged";
        }
        
        StringBuffer shows = new StringBuffer();
        shows.append("Battery status: " +   strStatus + "\n");
        shows.append("Battery HEALTH: " +  strHealth  + "\n");
        shows.append("Battery LEVEL: " +   batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)  + "%\n");
        shows.append("Battery PLUGGED: " +   strPlug  + "\n");
        shows.append("Battery PRESENT: " +   batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)  + "\n");
        shows.append("Battery TECHNOLOGY: " +   batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY)  + "\n");
        shows.append("Battery TEMPERATURE: " +   batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)/10  + " C\n");
        shows.append("Battery VOLTAGE: " +   ((float)batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1))/1000  + "\n");

        return shows.toString();
	}
}
